package com.dxq.test.view;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.dxq.test.App;
import com.dxq.test.R;

import org.jetbrains.annotations.NotNull;

/**
 * Author: zsh
 * Date: 2023/11/15
 * Describe: 仿微信右上角点击弹出菜单
 */
public class DevicePopWindow extends PopupWindow {

    public DevicePopWindow(Context context) {
        super(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        //这里要注意设置setOutsideTouchable之前要设置 setBackgroundDrawable()
        //否则点击外部无法关闭pop
        setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        setOutsideTouchable(true);
        //获取焦点设置为true 这样再次点击菜单时 就隐藏菜单
        setFocusable(true);
        View inflate = LayoutInflater.from(context).inflate(R.layout.pop_window_device, null);
        setContentView(inflate);

        TextView v1 = inflate.findViewById(R.id.tv_1);
        v1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mOnItemChildClickListener.onItemChildClick(v);
            }
        });
//        TextView v2 = inflate.findViewById(R.id.tv_2);
//        v2.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                mOnItemChildClickListener.onItemChildClick(v);
//            }
//        });
        TextView v3 = inflate.findViewById(R.id.tv_3);
        v3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mOnItemChildClickListener.onItemChildClick(v);
            }
        });
        TextView v4 = inflate.findViewById(R.id.tv_4);
        v4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mOnItemChildClickListener.onItemChildClick(v);
            }
        });

        //设置窗口进入和退出的动画
        setAnimationStyle(R.style.pop_add);
    }

    public interface OnItemChildClickListener {
        void onItemChildClick( @NonNull View view);
    }

    public OnItemChildClickListener mOnItemChildClickListener;

    public void setOnItemChildClickListener(OnItemChildClickListener listener) {
        this.mOnItemChildClickListener = listener;
    }
}

